#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX_NUM 1000000

// get random num between 0 and (num-1)
int getRand(int num)
{
    if(num <= 0) return 0;

    return rand() % num;    
}

int main(int argc, char *argv[])
{
    int n[10];
    int i, r;
    for(i = 0; i < 10; i++)
    {
        n[i] = 0;
    }
    i = MAX_NUM;
    srand(time(NULL));
    while(i)
    {
        r = getRand(10);
        if(r > 9) break;
        --i;
        n[r]++;
    }

    // check if error happend in getRand
    if(i)
        printf("Except i = 0, actual i = %d\n", i);

    for(i = 0; i < 10; i++)
        printf("%d count: %d\n", i, n[i]);

    return 0;
}
